package cate.common.table.farm.island.sheet;

import cate.common.table.ESheet;
import cate.common.table.farm.island.row.IslandMapGroupRow;
import cate.common.util.random.RWList;
import easy.java.dev.note.NoteClass;

import java.util.HashMap;
import java.util.Map;

@NoteClass(value = "迷失神庙地图分组")
public class IslandMapGroupSheet extends ESheet<IslandMapGroupRow> {

    @Override
    public String getSheetName() {
        return "迷失神庙地图分组";
    }

    @Override
    protected IslandMapGroupRow buildRow() {
        return new IslandMapGroupRow();
    }

    private Map<Integer, RWList<IslandMapGroupRow>> mapGroup;

    @Override
    protected void onLoaded() {
        mapGroup = new HashMap<>();
        for (IslandMapGroupRow row : this.getList()) {
            RWList<IslandMapGroupRow> rwList = mapGroup.get(row.group);
            if (rwList == null) {
                rwList = new RWList<>();
                mapGroup.put(row.group, rwList);
            }
            rwList.add(row);
        }
        mapGroup.values().forEach(RWList::setup);
    }

    /**
     * 随机选取一张地图
     *
     * @param group 分组
     * @return
     */
    public IslandMapGroupRow randomMap(int group) {
        RWList<IslandMapGroupRow> rwList = mapGroup.get(group);
        if (rwList == null) {
            return null;
        }
        return rwList.get();
    }
}
